package thread;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 09 - 12
 * Time: 20:20
 */
//实现线程安全版本的单例模式
class SingletonLazy {
    private static volatile SingletonLazy inStance;
    public static SingletonLazy getInStance() {
        if(inStance == null) {
            synchronized (SingletonLazy.class) {
                if(inStance == null) {
                    inStance = new SingletonLazy();
                }
            }
        }
        return inStance;
    }
    private SingletonLazy() {

    }
}
public class Demo6 {
    public static void main(String[] args) {
        SingletonLazy s1 = SingletonLazy.getInStance();
        SingletonLazy s2 = SingletonLazy.getInStance();
        System.out.println(s1 == s2);
    }
}